<?php
/**
 * Sakam - framework oriented trough models
 * 
 * @category   	Sakam
 * @package    	Sakam_Data
 * @author		Carlos Gonzalez <zahualli@gmail.com>
 * @copyright  	Copyright (c) 2009-2010 Carlos Gonzalez
 */
class Sakam_Data_Field
{
	/**
	 * Name of field
	 * @var string
	 * @access protected
	 */
	protected $_name = null;
	
	/**
	 * Type of field
	 * @var string
	 * @access protected
	 */
	protected $_type = null;
	
	/**
	 * Lenght of field
	 * @var int
	 * @access protected
	 */
	protected $_lenght = null;
	
	/**
	 * Is Key?
	 * @var string
	 * @access protected
	 */
	protected $_key  = null;
	
	/**
	 * @var 	Sakam_Data_Table_Interface
	 * @access	protected
	 */
	protected $_table = null;
	
	const TYPE_INT 			= 'int';
	const TYPE_SMALLINT 	= 'smallint';
	const TYPE_BIGINT	 	= 'bigint';
	const TYPE_CHAR 		= 'char';
	const TYPE_VARCHAR 		= 'varchar';
	const TYPE_FLOAT 		= 'float';
	const TYPE_DATE			= 'date';
	const TYPE_DATETIME		= 'datetime';
	
	
	/**
	 * Constructo of class
	 * @param	Sakam_Data_Interface_Interface	$table
	 * @param	string 							$name
	 * @param	string							$type
	 * @param	bool							$key
	 * @param	int								$lenght
	 * @access	public
	 * @return 	void
	 */
	public function __construct( Sakam_Data_Table_Interface $table, $name, $type='int', $key=false, $lenght=null )
	{
		$this->_table= $table;
		$this->_name = $name;
		$this->_type = $type;
		$this->_key  = $key;
		$this->_key  = $lenght;
	}
	
	/**
	 * Set name of field
	 * @param	string	$type
	 * @access	public
	 * @return 	void
	 */
	public function setName( $name )
	{
		$this->_name = $name;
	}
	
	/**
	 * Get name of field
	 * @access	public
	 * @return 	string
	 */
	public function getName()
	{
		return $this->_name;
	}
	
	/**
	 * Set type of field
	 * 
	 * @param	string	$type
	 * @return 	void
	 */
	public function setType( $type )
	{
		$this->_type = $type;
	}
	
	/**
	 * Get type of field
	 * @return 	string
	 */
	public function getType()
	{
		return $this->_type;
	}
	
	/**
	 * Set lenght of field
	 * @param	int		$lenght
	 * @access	public
	 * @return 	void
	 */
	public function setLenght( $lenght )
	{
		return $this->_lenght;
	}
	
	/**
	 * Get type of field
	 * @access	public
	 * @return 	int
	 */
	public function getLenght()
	{
		return $this->_lenght;
	}
	
	/**
	 * Get or Set key
	 * @access	public
	 * @return 	bool
	 */
	public function isKey( $key=null )
	{
		if(isset($key)) $this->_key = (bool)$key;
		else return $this->_key;
	}
	
	/**
	 * Get or Set fiel
	 * @access	public 
	 * @abstract
	 * @return 	string
	 */
	public abstract function getSQL();
}